package com.lingyuan.ums.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingyuan.common.core.domain.vo.ums.MemberAddressVo;
import com.lingyuan.common.core.domain.vo.ums.MemberVo;
import com.lingyuan.common.core.exception.ServiceException;
import com.lingyuan.common.core.utils.bean.BeanUtils;
import com.lingyuan.ums.domain.MemberAddressEntity;
import com.lingyuan.ums.domain.MemberEntity;
import com.lingyuan.ums.mapper.MemberAddressMapper;
import com.lingyuan.ums.mapper.MemberMapper;
import com.lingyuan.ums.service.MemberAddressService;
import com.lingyuan.ums.service.MemberService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName：MemberServiceImpl
 * @Author: LeiHao
 * @Date: 2024/9/21 12:08
 * @Description: 会员信息服务实现类
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberEntity> implements MemberService {

    /* *
     * @Title: findById
     * @Author: DELL
     * @Date: 2024-09-21 12:06:56
     * @Params: [id]
     * @Return: MemberVo
     * @Description: 根据id会员信息
     */
    @Override
    public MemberVo findMemberById(Long id) {
        MemberEntity memberEntity = this.getById(id);
        if (memberEntity == null) {
            throw new ServiceException("没有该用户信息");
        }
        MemberVo memberVo = new MemberVo();
        BeanUtils.copyProperties(memberEntity, memberVo);
        return memberVo;
    }


    /* *
     * @Title: findByUserName
     * @Author: DELL
     * @Date: 2024-09-23 14:24:57
     * @Params: [username]
     * @Return: MemberVo
     * @Description: 用户名查询用户信息
     */
    @Override
    public MemberVo findByUserName(String username) {
        MemberEntity memberEntity = this.getOne(new QueryWrapper<MemberEntity>().lambda().eq(MemberEntity::getUsername, username));
        MemberVo memberVo = new MemberVo();
        BeanUtils.copyProperties(memberEntity, memberVo);
        return memberVo;
    }
}
